package org.glut.controller;

import org.glut.bean.RF;
import org.glut.service.RFService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
/**
 * RDID
 * @author 啊林
 * @date 2022/1/10
 * @time 0:05
 */
public class RFController {
    @Autowired
    private RFService rfService;

    @RequestMapping("/rfline")
    public String rfline(){
        return "/myviews/rfline";
    }

    @RequestMapping("/rfpower")
    public String rfpower(){
        return "/myviews/rfpower";
    }

    /**
     * 获取RFIDbean
     * @return
     */
    @RequestMapping("/getRF")
    @ResponseBody
    public RF getRF(String id) {
        if ("1".equals(id)) {
            return RFService.rf1;
        }else{
            return RFService.rf2;
        }
    }


    /**
     * 获取RFID上传时间List
     * @return
     */
    @RequestMapping("/getrfTimeDate")
    @ResponseBody
    public List<String> getrfTimeDate(String id){
        List<String> timeList;
        if ("1".equals(id)) {
            timeList = rfService.rftimeList1;
        }else {
            timeList = rfService.rftimeList2;
        }
        if (timeList.size() > 30) {
//            List<String> list = timeList.subList(timeList.size() - 30, timeList.size() - 1);
//            rfService.timeList.remove(0);
//            rfService.timeList = new ArrayList<>(list);
            timeList.remove(0);
        }
        return timeList;
    }

    /**
     * 获取RFID上传电量List
     * @return
     */
    @RequestMapping("/getrfpowerDate")
    @ResponseBody
    public List<String> getrfpowerDate(String id){
        List<String> rfList;
        if ("1".equals(id)) {
            rfList = rfService.rfpower1;
        }else {
            rfList = rfService.rfpower2;
        }
        if (rfList.size() > 30) {
//                List<String> list = rfList.subList(rfList.size() - 30, rfList.size() - 1);
//                rfService.rfList = new ArrayList<>(list);
            int size = rfList.size();
            rfList = rfList.subList(size-30,size);
        }
        return rfList;
    }

}
